<!--
 * @Author: your name
 * @Date: 2021-09-26 20:50:30
 * @LastEditTime: 2021-10-27 10:16:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue_test\src\components\Student.vue
-->
<template>
  <div class="school">
    <h2>学校名称：{{ name }}</h2>
    <h2>学校地址：{{ address }}</h2>
  </div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
  name: "School",
  data() {
    return {
      name: "尚硅谷",
      address: "北京",
    };
  },
  mounted() {
    this.pubId = pubsub.subscribe("hello", (msg, data) => {
      console.log(this);
      console.log("有人发布了hello消息，hello消息的回调执行了！",msg,data)
    });
  },
  beforeDestroy() {
    pubsub.unsubscibe(this.pubId);
  },
};
</script>

<style scoped>
.school {
  background: skyblue;
  padding: 5px;
}
</style>
